package com.me.batm.models;

import com.badlogic.gdx.math.Vector2;
import com.me.batm.GameConstants;
import com.me.batm.Utils;
import com.me.batm.services.GameConfiguration;

public class Target extends Person {
	public static final float WIDTH=50f,HEIGHT=60f;
	public Vector2 center;
	public Vector2 p1,p2,p3,p4;
	public boolean isWalking;
	
	public float angerBar;
	public float conquerBar;
	
	public Target(float x, float y,Vector2 direction) {
		super(x, y, WIDTH,HEIGHT, direction);
		refreshPosition();
		isWalking = false;
		
		angerBar = 0f;
		conquerBar = 0f;
	}
	
	public void applyConquerDistance(float distance,float delta){
		float value = delta * distance * GameConfiguration.getConquerConstant();
		value = value * value;
		value /= GameConstants.ANGERCONQUER_CONSTANT;
		conquerBar += value;
	}
	public void applyAngerDistance(float distance,float delta){
		float value = delta * distance * GameConfiguration.getAngerConstant();
		value = value * value;
		value /= GameConstants.ANGERCONQUER_CONSTANT;
		angerBar += value;
	}
	
	public boolean isConquered(){
		return conquerBar >= 100f;
	}
	
	public boolean mustTeletransport(){
		return angerBar >= 100f;
	}
	
	private void refreshPosition(){
		center = new Vector2(shape.x + WIDTH / 2f, shape.y + HEIGHT/2f);

		p1 = Utils.rotateAround(new Vector2(shape.x,shape.y),center,getAngle());
		p2 = Utils.rotateAround(new Vector2(shape.x+Player.WIDTH,shape.y),center,getAngle());
		p3 = Utils.rotateAround(new Vector2(shape.x+Player.WIDTH,shape.y + Player.HEIGHT ),center,getAngle());
		p4 = Utils.rotateAround(new Vector2(shape.x,shape.y + Player.HEIGHT),center,getAngle());
	}

	public float getAngle(){
		return direction.angle();
	}
	
	public void update(float delta){		
		keyFrameTime += delta;
	}
}
